# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Sebastian Wicki <gandro@gmx.net>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=mpd
pkgver=0.23.15
case $pkgver in
*.*.*) _branch=${pkgver%.*};;
*.*) _branch=$pkgver;;
esac
pkgrel=4
pkgdesc="Music daemon that plays MP3, FLAC, Ogg Vorbis files and Audio CDs"
url="https://musicpd.org/"
pkgusers="mpd"
pkggroups="mpd audio"
# s390x: limited by pipewire
arch="all !s390x"
license="GPL-2.0-or-later"
makedepends="
	alsa-lib-dev
	avahi-dev
	boost-dev
	curl-dev
	expat-dev
	faad2-dev
	ffmpeg-dev
	flac-dev
	fmt-dev
	glib-dev
	gtest-dev
	icu-dev
	jack-dev
	lame-dev
	libao-dev
	libcap-utils
	libcdio-paranoia-dev
	libid3tag-dev
	libmad-dev
	libmodplug-dev
	libmpdclient-dev
	libnfs-dev
	libogg-dev
	libsamplerate-dev
	libshout-dev
	libvorbis-dev
	meson
	opus-dev
	pipewire-dev
	pulseaudio-dev
	py3-attrs
	py3-sphinx
	samba-dev
	soxr-dev
	wavpack-dev
	"
checkdepends="gtest"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-dbg $pkgname-openrc"
source="https://www.musicpd.org/download/mpd/$_branch/mpd-$pkgver.tar.xz
	stacksize.patch
	fmt11.patch
	mpd.initd
	mpd.confd
	"

# secfixes:
#   0:
#     - CVE-2020-7465
#     - CVE-2020-7466

build() {
	abuild-meson \
		-Dshout=enabled \
		-Dopus=enabled \
		-Dmodplug=enabled \
		-Dnfs=enabled \
		-Dsmbclient=enabled \
		-Dffmpeg=enabled \
		-Dlibmpdclient=enabled \
		-Dcdio_paranoia=enabled \
		-Dzeroconf=avahi \
		-Dtest=true \
		-Ddocumentation=enabled \
		-Dwavpack=enabled \
		-Dpipewire=enabled \
		-Dsnapcast=true \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# provide a config that works by default
	install -d "$pkgdir"/etc
	sed	-e 's:\#user.*:user\t\t"mpd":' \
		-e 's:\#log_file.*:log_file\t\t"syslog":' \
		doc/mpdconf.example > "$pkgdir"/etc/mpd.conf
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
	install -d -g audio -o mpd -m775 \
		"$pkgdir"/var/run/mpd \
		"$pkgdir"/var/log/mpd \
		"$pkgdir"/var/lib/mpd \
		"$pkgdir"/var/lib/mpd/.cache \
		"$pkgdir"/var/lib/mpd/playlists \
		"$pkgdir"/var/lib/mpd/music
}

sha512sums="
12329dbd0c1994c1bd95b88ce2a62a4c1d691b655e9e4fac7e9ef7066d0be3422b26fad3ea6ca144ba9b21add0a7c492c4f74fd2b68a1539bff2e0d2714db709  mpd-0.23.15.tar.xz
f60f6f3e921d20732c1a4c31a97f28660b43fd649e767d6c39661b6a90145231a79ad3f740ae0d706380b245ad040e98b661a513463c54cea161d1f64fc261e0  stacksize.patch
70be1c46cafc95751f6bc144f2263a3a6e1752f948005477edea15b07fd83959839c33d58021838af23bc25b6726c5e168a44dc7f23f138f811266da68df4039  fmt11.patch
3ee3a85b34d328090bc66892cba643443296bf126197f93becffa3d4c91742b600da5e17845337f17ac3714cbdcadde89bbd1bec797eb1966ab8208d7b221e7b  mpd.initd
60119784963ab3a745282816bfadced2b6a5b714a57f4f6eff9fb7b649fe7c22e7b840d4b40d607bc2a1392524081836d52ac04bd141caa50a034277bca3e7e1  mpd.confd
"
